// 本机
const domain = '<%=domain%>';
const if_url = domain + '/bdhapi';
const if_url_upload = domain + '/bdhapi/uploadfile';
const if_url_delete = domain + '/bdhapi/uploadfile/deleteFile';
const if_url_print = domain + '/bdhapi/printFile'

var winPlat = window.navigator.platform;
var isPhone = !(winPlat == 'Win32' || winPlat == 'Win64' || winPlat == 'MacIntel' || winPlat == 'Linux i686' || winPlat == 'Linux x86_64');

function changeFontSize() {
  var u = navigator.userAgent;
  let _fontSize = window.innerWidth * 16 * window.devicePixelRatio / 1920; //windows系统字号计算
  if ((u.indexOf('Android') >= 0 || u.indexOf('Adr') >= 0) || (!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/))) {
    _fontSize = window.innerWidth * 32 / 1920; //ios终端 or android终端
  }
  else if (/macintosh|mac os x/i.test(u)) {
    _fontSize = window.innerWidth * 16 / 1920; //Mac系统字号计算
  }
  document.documentElement.style.fontSize = _fontSize + "px";
}
changeFontSize();
window.onresize = function () {
  changeFontSize();
}
// $(window).resize(function () {
//   changeFontSize();
// });

//判断是否定义或存在
function isDefine(para) {
  if (typeof para === "undefined" || para === "" || para === "[]" || para === null || para === undefined || para === "undefined") {
    return false;
  } else if (typeof para == "number" || para == "number" || para == "null") {
    return true;
  } else if (para === null || para === undefined) {
    return true;
  } else {
    for (var o in para) {
      return true;
    }
    return false;
  }
}

//全局统一控制打印log日志--部署版本前请务必注释改行
function hdp_console(logObj) {
  // console.log(logObj);
}

function GetIEVersion() {
  var win = window;
  var doc = win.document;
  var input = doc.createElement("input");
  //"!win.ActiveXObject" is evaluated to true in IE11
  if (win.ActiveXObject === undefined) return null;
  //if (!win.XMLHttpRequest) return 6;
  if (document.all && document.compatMode && !window.XMLHttpRequest) {
    return 6;
  }
  // if (!doc.querySelector) return 7;
  if (document.all && window.XMLHttpRequest && !document.querySelector) {
    return 7;
  }
  // if (!doc.addEventListener) return 8;
  if (document.all && document.querySelector && !document.addEventListener) {
    return 8;
  }
  //if (!win.atob) return 9;
  if (document.all && document.addEventListener && !window.atob) {
    return 9;
  }
  //"!doc.body.dataset" is faster but the body is null when the DOM is not
  //ready. Anyway, an input tag needs to be created to check if IE is being
  //emulated
  //if (!input.dataset) return 10;
  if (document.all && document.addEventListener && window.atob && !input.dataset) {
    return 10;
  }
  return 11;
}
var IEVersion = GetIEVersion();
if (isDefine(IEVersion) && IEVersion < 10) {
  document.getElementById("myPage").style.display = "none";
  alert("IE浏览器版本过低，请使用IE10及以上浏览器或使用其他浏览器访问。");
} else if (!window.applicationCache) {
  //alert("该浏览器不支持H5页面");
}
if (!String.prototype.includes) {
  String.prototype.includes = function (search, start) {
    'use strict';
    if (typeof start !== 'number') {
      start = 0;
    }
    if (start + search.length > this.length) {
      return false;
    } else {
      return this.indexOf(search, start) !== -1;
    }
  };
}

// //根据当前屏幕大小自适应网站排版布局
// function resizeWindow() {
//   if (!isPhone) { //pc端浏览器放大缩小适配
//     var screenWidthInFooter = $(window).width();
//     if (screenWidthInFooter < 1080) {
//       //头部适配
//       $(".top-tips").addClass("uhide");
//       $(".menus").addClass("uhide");
//       $(".tips-app").addClass("hdp-uf-show");
//       $(".menus-app").removeClass("uhide");
//       $(".hdp-content").addClass("hdp-content-resize");
//     } else {
//       //头部适配--恢复
//       $(".top-tips").removeClass("uhide");
//       $(".menus").removeClass("uhide");
//       $(".tips-app").removeClass("hdp-uf-show");
//       $(".menus-app").addClass("uhide");
//       $(".hdp-content").removeClass("hdp-content-resize");
//     }
//   }
// }

//重置用户本地存储
function resetUserlocalStorage() {
  localStorage.setItem('isLogined', "");
}

//退出用户的登录状态
function doLogOut() {
  resetUserlocalStorage();
  window.location.href = domain + "/logout";
}

//过滤数字，添加分隔符
function filterNum(numStr) {
  if (isDefine(numStr)) {
    let source = String(numStr).split(".");//按小数点分成2部分
    source[0] = source[0].replace(new RegExp('(\\d)(?=(\\d{3})+$)', 'ig'), "$1,");//只将整数部分进行都好分割
    numStr = source.join(".");//再将小数部分合并进来
  }
  return numStr;
}

//时间过滤器
function filterDate(type, date) {
  var dateStr = "";
  if (isDefine(date)) {
    date = (new Date(date)).getTime() - 60 * 60 * 1000 * 8;
    date = new Date(date);
    dateStr = date.getFullYear();
    dateStr += "-";
    dateStr += (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
    dateStr += "-";
    dateStr += date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
    dateStr += " ";
    dateStr += date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
    dateStr += ":";
    dateStr += date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
  }
  return dateStr;
}

//页面整体滑动到顶部
function scrollTop() {
  $('html, body').animate({ scrollTop: 0 }, 'slow');
}

//设置请求头
function setResHeader() {
  let LanguageType = localStorage.getItem("DTT_TAX_Portal_Language");
  return {
    'Access-Control-Allow-Origin': '*',
    lang: LanguageType ? LanguageType : "cn",
  };
}

//统一跳转workSpace操作界面
function goToMyTaskPage() {
  //子项目 工作台页需要修改此处
  window.location.href = "/home";
}

//跳转首页
function goHomePage() {
  window.location.href = domain + "/home";
}

function deepCopy(p, c) {
  var c = c || {};
  for (var i in p) {
    if (!p.hasOwnProperty(i)) {
      continue;
    }
    if (typeof p[i] === 'object') {
      c[i] = (p[i].constructor === Array) ? [] : {};
      deepCopy(p[i], c[i]);
    } else {
      c[i] = p[i];
    }
  }
  return c;
}

// function getLanguageType() {
//   let LanguageType = localStorage.getItem("DTT_TAX_Portal_Language");
//   return LanguageType ? LanguageType : "cn";
// }

function stringUtil(value) {
  if (value === null || value === undefined || value === '' || JSON.stringify(value) === '{}') {
    return false
  }
  return true
}

//给sessionStorage存值
function setContextData(key, value) {
  if (typeof value == "string") {
    sessionStorage.setItem(key, value);
  } else {
    sessionStorage.setItem(key, JSON.stringify(value));
  }
}

// 从sessionStorage取值
function getContextData(key) {
  const str = sessionStorage.getItem(key);
  if (typeof str == "string") {
    try {
      return JSON.parse(str);
    } catch (e) {
      return str;
    }
  }
  return;
}
function getUrlParam(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  var r = window.location.search.substr(1).match(reg);
  if (r != null) return unescape(r[2]); return null;
}
function setUrlParam(name, val, url) {
  if (typeof name !== 'string') return false;
  if (!url) url = window.location.href;
  var _name = name.replace(/[\[\]]/g, '\\$&');
  var value = name + '=' + encodeURIComponent(val);
  var regex = new RegExp(_name + '=[^&]*');
  var urlArr = url.split('#');
  var result = '';
  if (regex.exec(url)) {
    result = url.replace(regex, value);
  } else {
    result = urlArr[0] + (url.indexOf("?") < 0 ? "?" : "&") + value + (urlArr[1] || '');
  }
  return result;
}
//key:cooke名称，value:cookie值，exprie:毫秒数-/+都行
function setCookie(key, value, exprie) {
  if (key) {
    exprie = exprie ? exprie : 30 * 24 * 60 * 60 * 1000;
    var d = new Date();
    d.setTime(d.getTime() + exprie);
    document.cookie = key + "=" + value + ";path=/;expires=" + d.toUTCString();
  }
}
if (!localStorage.getItem('DTT_TAX_Portal_Language')) {
  localStorage.setItem("DTT_TAX_Portal_Language", 'cn');
}

// 对Date的扩展，将 Date 转化为指定格式的String 
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符， 
// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字) 
// 例子： 
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 
// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18 
Date.prototype.Format = function (fmt) {
  var o = {
    "M+": this.getMonth() + 1,                    //月份 
    "d+": this.getDate(),                         //日 
    "H+": this.getHours(),                        //小时 
    "m+": this.getMinutes(),                      //分 
    "s+": this.getSeconds(),                      //秒 
    "q+": Math.floor((this.getMonth() + 3) / 3),  //季度 
    "S": this.getMilliseconds()                   //毫秒 
  };
  if (/(y+)/.test(fmt))
    fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt))
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
}